package first.web;



import first.utils.UploadUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 项目名称：File
 * 类 名 称：${NAME}
 * 类 描 述：TODO
 * 创建时间：2019-12-02 10:51
 * 创 建 人：jacksonmike
 */
@WebServlet(name = "ServletListFiles", value = "/list")
public class ServletListFiles extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Map<String, String> maps = new HashMap<>();
        String basePath = this.getServletContext().getRealPath("/WEB-INF/upload");
        System.out.println(basePath);
        UploadUtils.listFiles(new File(basePath), maps);
        request.setAttribute("maps", maps);
        for (Map.Entry<String, String> entry : maps.entrySet()) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }
        request.getRequestDispatcher("/list.jsp").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
